/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ejb;

import java.util.Hashtable;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import zy.ejb2.EJB2Factory;

/**
 *
 * @author Administrator
 */
public class ServiceFactory {

    public static Object getService(String beanName, Class serviceClass) {
    	
    	
    	
        Object retService = null;
        Hashtable jndiProperties = new Hashtable();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        Context context;
        try {
            context = new InitialContext(jndiProperties);

            String appName = "ear1";
            String moduleName = "ejb1";// 工程名 
            String distinctName = ""; 
            String jndi = "ejb:" + appName + "/" + moduleName + "/" + distinctName
                    + "/" + beanName + "!" + serviceClass.getName();

            retService = context.lookup(jndi);

            Object obj1 = context
					.lookup("java:global/ear1/ejb1/Hello!zy.ejb.HelloLocal");
			Object obj2 = context
					.lookup("java:app/ejb1/Hello!zy.ejb.HelloLocal");
			Object obj3 = context
					.lookup("java:module/Hello!zy.ejb.HelloLocal");

			Object obj4 = context
					.lookup("java:global/ear1/ejb1/Hello!zy.ejb.HelloRemote");
			Object obj5 = context
					.lookup("java:app/ejb1/Hello!zy.ejb.HelloRemote");
			Object obj6 = context
					.lookup("java:module/Hello!zy.ejb.HelloRemote");
			Object obj7 = context
					.lookup("java:jboss/exported/ear1/ejb1/Hello!zy.ejb.HelloRemote");
            
            
            return retService;
        } catch (NamingException ex) {
            ex.printStackTrace();
            Logger.getLogger(ServiceFactory.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
}
